﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using MyCommerce.Presentation.Stores.IViews;
using MyCommerce.Business.Stores;

namespace MyCommerce.Presentation.Stores.Presenters
{
    public class SaleProductChangesPresenter
    {
        private ISaleProductChanges pViewToPresent;

        public SaleProductChangesPresenter(ISaleProductChanges vIView)
        {
            pViewToPresent = vIView;
            pViewToPresent.OnCancel += new EventHandler(pViewToPresent_OnCancel);
            pViewToPresent.OnLoadDetails += new EventHandler(pViewToPresent_OnLoadDetails);
            pViewToPresent.OnLoadSales += new EventHandler(pViewToPresent_OnLoadSales);
            pViewToPresent.OnSave += new EventHandler(pViewToPresent_OnSave);
        }

        void pViewToPresent_OnSave(object sender, EventArgs e)
        {
            pViewToPresent.CLoseView(true); 
        }

        void pViewToPresent_OnLoadSales(object sender, EventArgs e)
        {
            pViewToPresent.CancelView(false);
            SalesOrderManager orderMgr = new SalesOrderManager();
            pViewToPresent.DtSalesOrders = orderMgr.GetAllOrderSalesByDate(pViewToPresent.SelectedDate, pViewToPresent.IdDealerStore);
        }

        void pViewToPresent_OnLoadDetails(object sender, EventArgs e)
        {
            SalesOrderManager orderMgr = new SalesOrderManager();
            pViewToPresent.DtSaleDetails = orderMgr.GetSaleDetailsByOrderSale(pViewToPresent.IdSaleOrderSelected);
        }

        void pViewToPresent_OnCancel(object sender, EventArgs e)
        {
            pViewToPresent.CancelView(true);   
        }
    }
}
